//
//  AUNetworkModule.swift
//  AwesomeUNetworkModule_Example
//
//  Created by Miss_Special on 2018/4/13.
//  Copyright © 2018 CocoaPods. All rights reserved.
//

import Alamofire

public enum RequestType {
    case get
    case post
}

public struct AUNetworkModule {
    
    public static func requestData(_ type: RequestType,
                           urlString: String,
                           parameters: [String: String]? = nil,
                           finishedCallBack: @escaping (_ result: Any) -> ())
    {
        
        let method = type == RequestType.get ? HTTPMethod.get : HTTPMethod.post
        
        Alamofire.request(urlString, method: method, parameters: parameters).responseJSON { (response) in
            guard let result = response.result.value else {
                print("网络请求错误: " + response.error.debugDescription)
                return
            }
            
            finishedCallBack(result)
        }
    }
}
